package com.shop2cn.iapi.promotion.testcase;

import java.util.Arrays;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.promotion.parameter.GetPromotionPolicyBySellerReq;
import com.shop2cn.iapi.promotion.parameter.GetPromotionPolicyBySellerResp;
import com.shop2cn.iapi.promotion.parameter.PromotionPolicyDto;
import com.shop2cn.iapi.promotion.serivce.GetPromotionBySellerIdCall;
import com.shop2cn.iapi.promotion.serivce.PromotionInfoVerify;
import com.shop2cn.iapi.sellerpromotion.parameter.CreatePromotionBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JSellerPromotionCallService;
import com.ymttest.business.service.SellerPromotionCallService;
import com.ymttest.business.service.Shop2cnSellerPromotionCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.compare.AssertHelper;
/**
*获取买手当前有效的促销活动
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetPromotionBySellerId{
	private static GetPromotionPolicyBySellerReq getpromotionbyselleridBean;
	private static GetPromotionBySellerIdCall getpromotionbyselleridCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买手当前有效的促销活动");
	}

	@Before
	public void caseUp() {
		getpromotionbyselleridBean=new GetPromotionPolicyBySellerReq();
		getpromotionbyselleridCall=new GetPromotionBySellerIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getpromotionbyselleridCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPromotionBySellerId_001() {
		Logger.start(true,"获取买手当前有效的促销活动");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
	//		int sellerid=1;
			getpromotionbyselleridBean.setSellerId(sellerid);
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			GetPromotionPolicyBySellerResp newPromotionPolicys1 = getpromotionbyselleridCall.getData();
			
			PromotionInfoVerify promotionInfoVerify = new PromotionInfoVerify();
			
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");

			if(newPromotionPolicys1.getPromotionPolicyDtos().size()>0)
			{
				for (PromotionPolicyDto promotionPolicy : newPromotionPolicys1.getPromotionPolicyDtos()) {
					promotionInfoVerify.verifyPromotionPolicyInDB(promotionPolicy,false);
				}
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionBySellerId_003() {
		Logger.start(true,"获取买手当前有效的促销活动-seller不传");
		try {
//			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));
//			getpromotionbyselleridBean.setSellerId(sellerid);
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			GetPromotionPolicyBySellerResp newPromotionPolicys1 = getpromotionbyselleridCall.getData();
						
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionbyselleridCall.getData().getPromotionPolicyDtos(), "验证返回data");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionBySellerId_004() {
		Logger.start(true,"获取买手当前有效的促销活动-seller传不存在");
		try {
//			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));
			getpromotionbyselleridBean.setSellerId(9999);
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			GetPromotionPolicyBySellerResp newPromotionPolicys1 = getpromotionbyselleridCall.getData();
						
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionbyselleridCall.getData().getPromotionPolicyDtos(), "验证返回data");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetPromotionBySellerId_005() {
		Logger.start(true,"获取买手当前有效的促销活动-活动已取消");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			Shop2cnSellerPromotionCallService.EndAllEnablePromotion(sellerid);

			getpromotionbyselleridBean.setSellerId(sellerid);
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			GetPromotionPolicyBySellerResp newPromotionPolicys1 = getpromotionbyselleridCall.getData();
						
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionbyselleridCall.getData().getPromotionPolicyDtos(), "验证返回data");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetPromotionBySellerId_006() {
		Logger.start(true,"获取买手当前有效的促销活动-活动未开始");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);

			getpromotionbyselleridBean.setSellerId(sellerid);
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			GetPromotionPolicyBySellerResp newPromotionPolicys1 = getpromotionbyselleridCall.getData();
						
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionbyselleridCall.getData().getPromotionPolicyDtos(), "验证返回data");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPromotionBySellerId_007() {
		Logger.start(true,"获取买手当前有效的促销活动-查看有效商品");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);

			getpromotionbyselleridBean.setSellerId(sellerid);
			getpromotionbyselleridBean.setShowProduct(true);
			
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			GetPromotionPolicyBySellerResp newPromotionPolicys1 = getpromotionbyselleridCall.getData();
			
			PromotionInfoVerify promotionInfoVerify = new PromotionInfoVerify();
			
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");

			for (PromotionPolicyDto promotionPolicy : newPromotionPolicys1.getPromotionPolicyDtos()) {
				promotionInfoVerify.verifyPromotionPolicyInDB(promotionPolicy);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_GetPromotionBySellerId_008() {
		Logger.start(true,"获取买手当前有效的促销活动-前端debug");
		try {
			Integer sellerid =500041475 ;
//			String pid =TestDataManager.getRandomUUID().toString();
//			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
//			createpromotionBean.setProductIdList(Arrays.asList(pid));
//			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
	//		int sellerid=1;
			getpromotionbyselleridBean.setSellerId(sellerid);
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			GetPromotionPolicyBySellerResp newPromotionPolicys1 = getpromotionbyselleridCall.getData();
			
			PromotionInfoVerify promotionInfoVerify = new PromotionInfoVerify();
			
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");

			if(newPromotionPolicys1.getPromotionPolicyDtos().size()>0)
			{
				for (PromotionPolicyDto promotionPolicy : newPromotionPolicys1.getPromotionPolicyDtos()) {
					promotionInfoVerify.verifyPromotionPolicyInDB(promotionPolicy,false);
				}
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPromotionBySellerId_009() {
		Logger.start(true,"获取买手当前有效的促销活动-是否显示在首页ShowHomePage=false 返回全部 新增20200729");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			createpromotionBean.setShowHomePage(true);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
	//		int sellerid=1;
			getpromotionbyselleridBean.setSellerId(sellerid);
			getpromotionbyselleridBean.setShp(false);//false 全都出来
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			GetPromotionPolicyBySellerResp newPromotionPolicys1 = getpromotionbyselleridCall.getData();
			
			PromotionInfoVerify promotionInfoVerify = new PromotionInfoVerify();
			
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");

			if(newPromotionPolicys1.getPromotionPolicyDtos().size()>0)
			{
				for (PromotionPolicyDto promotionPolicy : newPromotionPolicys1.getPromotionPolicyDtos()) {
					promotionInfoVerify.verifyPromotionPolicyInDB(promotionPolicy,false);
				}
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPromotionBySellerId_010() {
		Logger.start(true,"获取买手当前有效的促销活动-是否显示在首页ShowHomePage=true 新增20200729");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			createpromotionBean.setShowHomePage(false);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
	//		int sellerid=1;
			getpromotionbyselleridBean.setSellerId(sellerid);
			getpromotionbyselleridBean.setShp(true);//false 全都出来
			getpromotionbyselleridCall.setData(getpromotionbyselleridBean);
			getpromotionbyselleridCall.callService();	
			
			Logger.verifyEquals("200", getpromotionbyselleridCall.getCode(), "验证返回Code");
			
			Logger.verifyEquals(0, getpromotionbyselleridCall.getData().getPromotionPolicyDtos().size(), "验证返回PromotionPolicyDtos为空");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}